{# djlint:off #}

{% macro export_button(export_url, text="Export") %}
  <a class="btn btn-outline btn-info" href="{{ export_url }}" download>
    {{ heroicon_outline("document-arrow-down", class="h-5 w-5") }}
    {{ text }}
  </a>
{% endmacro %}

{% macro import_button(import_url) %}
  <button hx-get="{{ import_url }}" class="btn btn-outline btn-accent">
    {{ heroicon_outline("document-arrow-up", class="h-5 w-5") }}
    Import
  </button>
{% endmacro %}

{% macro action_button(action, item_id) %}
  {% if item_id %}
    {% if action.url.endswith('/') %}
      {% set action_url = action.url ~ item_id %}
    {% else %}
      {% set action_url = action.url ~ '/' ~ item_id %}
    {% endif %}
  {% else %}
    {% set action_url = action.url %}
  {% endif %}
  <div class="tooltip" data-tip="{{ action.label }}">
  {% if action.type == 'link' %}
  <a href="{{ action_url }}" class="btn btn-ghost btn-sm {{ action.class }}">
       {{ heroicon_outline(action.icon) }}
  </a>
  {% elif action.type == 'function' %}
    <button
      type="button"
      class="btn btn-ghost btn-sm {{ action.class }}"
      @click.stop="{{ action.function }}('{{ action_url }}')"
    >
      {{ heroicon_outline(action.icon) }}
    </button>
  {% else %}
  <button class="btn btn-ghost btn-sm {{ action.class }}"
          hx-{{ action.method }}="{{ action_url }}"
          {% if action.push_url %}hx-push-url="true" {% endif %}
          {% if action.hx_target_error %}hx-target-error="{{ action.hx_target_error }}" {% endif %}
          {% if action.hx_target %}hx-target="{{ action.hx_target }}" {% endif %}
          {% if action.hx_swap %}hx-swap="{{ action.hx_swap }}" {% endif %}
          {% if action.confirm %}hx-confirm="{{ action.confirm }}" {% endif %}
          {% if action.data_attr %}{{ action.data_attr }} {% endif %}
          >
       {{ heroicon_outline(action.icon) }}
  </button>
  {% endif %}
  </div>
{% endmacro %}

{% macro state_toggle_button(current_state, hx_val_true, hx_val_false, text_true, text_false, hx_target, action_url, action_method='post') %}
<div class="join">
  <button type="button"
          hx-{{ action_method }}="{{ action_url }}"
          hx-vals="{{ hx_val_true }}"
          hx-target="{{ hx_target }}"
          class="btn btn-sm join-item {% if current_state == true %}btn-active btn-success{% endif %}">{{ text_true }}
  </button>
  <button type="button"
          hx-{{ action_method }}="{{ action_url }}"
          hx-vals="{{ hx_val_false }}"
          hx-target="{{ hx_target }}"
          class="btn btn-sm join-item {% if current_state == false %}btn-active{% endif %}">{{ text_false }}
  </button>
</div>
{% endmacro %}

{# djlint:on #}
